package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.model.ApplyModel;
import com.zr.model.UserModel;
/**
 * 学生申请住宿的调配者
 * @author 洪英杰
 *
 */
import com.zr.service.ApplyinDormService;
public class ApplyinDormController extends HttpServlet{
	ApplyinDormService ads=new ApplyinDormService();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//从session中获取学生的学号
		
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		HttpSession session=req.getSession();		
		UserModel user1=(UserModel)session.getAttribute("usermodel");
		int sid=user1.getSid();
		//获取申请寝室的编号
		String afhidStr=req.getParameter("afhid");
		int afhid=Integer.parseInt(afhidStr);
		String aidStr=req.getParameter("aid");
		int aid=Integer.parseInt(aidStr);
		String bfhidStr=req.getParameter("bfhid");
		int bfhid=Integer.parseInt(bfhidStr);
		
		ApplyModel am=new ApplyModel();
		am.setAid(aid);
		am.setSid(sid);
		am.setBfhid(bfhid);
		am.setAfhid(afhid);
		
		boolean flag=ads.applyInfo(sid, afhid);
		PrintWriter pw=resp.getWriter();
		if(flag)
		{
			pw.write("提交成功!");
		}
		

	}
}
